'use strict';

const BaseController = require('../base');

class OrderItemController extends BaseController {
  static get serviceName() {
    return 'business.orderItem';
  }

  // 获取订单的订单项列表
  async orderItems() {
    const { ctx } = this;
    const { orderId } = ctx.params;
    const result = await this.service.getItemsByOrder(orderId);
    ctx.success(result);
  }

  // 批量创建订单项
  async batchCreate() {
    const { ctx } = this;
    const data = ctx.request.body;
    const result = await this.service.batchCreate(data);
    ctx.success(result);
  }

  // 获取订单项详情（包含商品信息）
  async detail() {
    const { ctx } = this;
    const { id } = ctx.params;
    const result = await this.service.getDetailWithProduct(id);
    ctx.success(result);
  }

  // 获取订单项统计信息
  async statistics() {
    const { ctx } = this;
    const { orderId } = ctx.params;
    const result = await this.service.getOrderStatistics(orderId);
    ctx.success(result);
  }
}

module.exports = OrderItemController; 